package com.weipai.demo.bean;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class FileUploadBean {
	
		private static String FILE_SAVE_BASE;
		private static String WIDTH_FILE_MID;
		private static String HIGHT_FILE_MID;
		private static String WIDTH_FILE_MIN;
		private static String HIGHT_FILE_MIN;
		private static String ZOOM_FILE;
		private static String DOWN_BASE_URL ;
		static {
			Properties prop = new Properties();
			InputStream is = FileUploadBean.class
					.getClassLoader().getResourceAsStream("upload-set.properties");
			try {
				prop.load(is);
				FILE_SAVE_BASE = prop.getProperty("file.save_base");				
				WIDTH_FILE_MID = prop.getProperty("file.width_upload_file_mid");
				HIGHT_FILE_MID = prop.getProperty("file.hight_upload_file_mid");
				WIDTH_FILE_MIN = prop.getProperty("file.width_upload_file_min");
				HIGHT_FILE_MIN = prop.getProperty("file.hight_upload_file_min");
				ZOOM_FILE = prop.getProperty("file.zoom_whether");
				DOWN_BASE_URL = prop.getProperty("file.down_base_url");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		public static String getFILE_SAVE_BASE() {
			return FILE_SAVE_BASE;
		}
		public static String getWIDTH_FILE_MID() {
			return WIDTH_FILE_MID;
		}
		public static void setWIDTH_FILE_MID(String wIDTH_FILE_MID) {
			WIDTH_FILE_MID = wIDTH_FILE_MID;
		}
		public static String getHIGHT_FILE_MID() {
			return HIGHT_FILE_MID;
		}
		public static void setHIGHT_FILE_MID(String hIGHT_FILE_MID) {
			HIGHT_FILE_MID = hIGHT_FILE_MID;
		}
		public static String getWIDTH_FILE_MIN() {
			return WIDTH_FILE_MIN;
		}
		public static void setWIDTH_FILE_MIN(String wIDTH_FILE_MIN) {
			WIDTH_FILE_MIN = wIDTH_FILE_MIN;
		}
		public static String getHIGHT_FILE_MIN() {
			return HIGHT_FILE_MIN;
		}
		public static void setHIGHT_FILE_MIN(String hIGHT_FILE_MIN) {
			HIGHT_FILE_MIN = hIGHT_FILE_MIN;
		}
		public static String getZOOM_FILE() {
			return ZOOM_FILE;
		}
		public static void setZOOM_FILE(String zOOM_FILE) {
			ZOOM_FILE = zOOM_FILE;
		}
		
		public static String getDOWN_BASE_URL() {
			return DOWN_BASE_URL;
		}
		/**
		 * 生成下载地址
		 * @param path
		 * @return
		 */
		public static String createImgDownUrl(String path){
			//return DOWN_BASE_URL+path ;
			return path;
		}
		
		/**
		 * 
		 * @MethodName: getExt
		 * @Description: 生成中图名
		 * @2016年8月12日 下午6:51:41
		 * @author duxiaozheng
		 */
		public static String getMidName(String path){
			int index = path.lastIndexOf('.');
			String midString = "_mid";
			if(index!=-1){
				String extString = path.substring(index);
				String pathPre = path.substring(0,index);
				return pathPre+midString+extString;
			}
			return path+midString;
		}
		
		/**
		 * 
		 * @MethodName: getExt
		 * @Description: 生成小图名
		 * @2016年8月12日 下午6:51:41
		 * @author duxiaozheng
		 */
		public static String getMinName(String path){
			int index = path.lastIndexOf('.');
			String midString = "_min";
			if(index!=-1){
				String extString = path.substring(index);
				String pathPre = path.substring(0,index);
				return pathPre+midString+extString;
			}
			return path+midString;
		}
		
		/**
		 * 
		 * @MethodName: getExt
		 * @Description: 根据小、中图生成原图名
		 * @2016年8月12日 下午6:51:41
		 * @author duxiaozheng
		 */
		public static String getYuanName(String path){
			int index = path.lastIndexOf('.');
			if(index!=-1){
				String extString = path.substring(index);
				String pathPre = "";
				if(path.lastIndexOf('_')!=-1){
					pathPre = path.substring(0,path.lastIndexOf('_'));
					return pathPre+extString;
				}else{
					return path;
				}								
			}
			return path;
		}
		
		public static void main(String[] args) {
			String path = "http://localhost:8080/trademake/image/2016/08/12/56fds65gvd56gbv5c.jpg";
			System.out.println(getMidName(path));
			
		}
		
}
